package com.example.cloudmusicserve.service;

import com.example.cloudmusicserve.dao.MusicDao;
import com.example.cloudmusicserve.entity.RecentPlay;
import com.example.cloudmusicserve.util.FilerRecentPlay;
import com.example.cloudmusicserve.util.Time;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.List;


/**
 * @description: MusicSerivce
 * @author: xiaoyuan
 * @time: 2023/5/29
 */
@Service
public class MusicSerivce {

    //注入音乐接口
    @Resource
    MusicDao musicDao;
    //注入过滤接口
    @Resource
    FilerRecentPlay filerRecentPlay;

    public Integer addRecentPlay(RecentPlay recentPlay){
        //获取当前的时间戳
        long time = System.currentTimeMillis();
        String begintime = String.valueOf(time);
        String endTime = new BigInteger(begintime)
                .add(new BigInteger(Time.FIVE)).toString();
        recentPlay.setEndTime(endTime);
        //进行数据的过滤和获取大于四天的历史记录
        filerRecentPlay.deleteOvertimeMusic(recentPlay);

        return musicDao.addMusicRecord(recentPlay);
    }

    public List<RecentPlay> queryByUsername(RecentPlay recentPlay){
        return musicDao.queryByUsername(recentPlay);
    }

}
